#pragma semicolon 1
//強制1.7以後的新語法
#pragma newdecls required
#include <sourcemod>
#include <sdktools>



#define CVAR_FLAGS	FCVAR_NOTIFY
#define TankSound	"player/tank/voice/pain/tank_fire_08.wav"
ConVar g_hTankSwitchs;
int    g_iTankSwitchs;



public Plugin myinfo = 
{
	name = "l4d2_tank_sound",
	author = "豆瓣酱な",
	description = "坦克出生播放声音&&丢石头播放声音.",
	version = "1.0",
	url = "https://gitee.com/sweet-and-sour-bombs"
};

public void OnPluginStart()
{
	g_hTankSwitchs		= CreateConVar("l4d2_tank_Switchs", 		"1", 	"插件启用或禁用? 0=禁用, 1=启用.", CVAR_FLAGS);
	HookEvent("tank_spawn", Event_TankSpawn); //坦克出生事件.
	HookEvent("ability_use", Event_TankSpawn); //坦克丢石头事件.
	//AutoExecConfig(true, "l4d2_tank_sound");//生成指定文件名的CFG.
	
	
	g_hTankSwitchs.AddChangeHook(iHealthConVarChanged);
}

public void OnMapStart()
{
	iHealthCvars();
	PrecacheSound(TankSound);

	
}

public void iHealthConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
	iHealthCvars();
}

void iHealthCvars()
{
	g_iTankSwitchs	= g_hTankSwitchs.IntValue;

}

public void Event_TankSpawn(Event event, const char[] name, bool dontBroadcast)
{
	if (g_iTankSwitchs == 0)
		return;
	
	int client = GetClientOfUserId(event.GetInt("userid"));
	
	if (IsValidTank(client))
	{
		EmitSoundToAll(TankSound);//给所有玩家播放声音.
	}
}


stock bool IsValidClient(int client)
{
	return client > 0 && client <= MaxClients && IsClientInGame(client);
}


stock bool IsValidTank(int client)
{
	return IsValidClient(client) && GetClientTeam(client) == 3 && GetEntProp(client, Prop_Send, "m_zombieClass") == 8 && IsPlayerAlive(client);
}



